package com.zrc.superframe_base.mvx.mvp

import android.os.Bundle
import androidx.annotation.LayoutRes
import com.zrc.superframe_base.mvx.base.BaseActivity


/**
 * @Author: superman
 * @CreateTime: 2020/7/4
 * @Describe: MVP模式Activity基类
 */
@Suppress("UNCHECKED_CAST")
abstract class BaseMvpActivity<V, P : BasePresenter<V>?> : BaseActivity() {

    var mPresenter: P? = null

    protected abstract fun createPresenter(): P?

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mPresenter = createPresenter()
        mPresenter?.attachView(this as V)
        setContentView(getLayoutId())
        initView()
        initListener()
        initData()
    }

    @LayoutRes
    abstract fun getLayoutId(): Int

    open fun initView(){}

    open fun initListener(){}

    open fun initData(){}

    override fun onDestroy() {
        super.onDestroy()
        mPresenter?.detachView()
    }
}